<!DOCTYPE html>
<html lang="no">
    <head>
      <meta charset="utf-8">  
      <title>ejeje: {% block title %}Søk i norske postjournaler{%endblock%}</title>
      
      <link rel="stylesheet" type="text/css" href="/media/css/bootstrap.min.css">
      <link rel="stylesheet" type="text/css" href="/media/css/ejeje.css">
      <script type="text/javascript" src="/media/jquery.min.js"></script>
      <script type="text/javascript" src="/media/jquery.ba-hashchange.js"></script>
      <script type="text/javascript" src="/media/ejeje.js"></script>
      <script type="text/javascript" src="/media/bootstrap.min.js"></script>
{%block head%}{%endblock%}

<script type="text/javascript">

$(function() {
  $("body").bind("authenticated", function(event, bool) { 
    if(bool) {
      $(".require-authenticated").show();
      $("#login-box").hide();
      $("#logout-box").show();
    } else {
      $(".require-authenticated").hide();
      $("#login-box").show();
      $("#logout-box").hide();
    }
  });
  $("#login").click(function(ev) { $("#login-form").show("fast"); });
  $("#login-cancel").click(function(ev) { $("#login-form").hide("fast"); });
  $("#login-send").click(function(ev) {
    var username = $("#login-username").val();
    var password = $("#login-password").val();
    if(!(username.length && password.length)) {
      $.facebox("Username and password!!");
      return false;
    }
    $.post('/innlogging.json', 
           {'username':username, 'password':password},
           function(data, textStatus, xhr) {
             //successfully logged in
             $("body").trigger("authenticated", [ true ]);
           });
  });
  $("#logout-send").click(function(ev) {
    $.get('/utlogging',
          function(data, textStatus, xhr) {
             //successfully logged out
             $("body").trigger("authenticated", [ false ]);
             $("#logout-box").hide();
             $("#login-box").show();
          });
  });
  $("#meny a").each(function(idx, el) {
    var EL = $(el);
    if("/" + window.location.pathname.split("/")[1] === EL.attr("href")) {
        EL.parent().addClass("active");
    }
  });

});
  {% block script %}{% endblock %}
</script>
    </head>

    <body>
    {% if error_message %}<p class="alert alert-error"><strong>{{ error_message }}</strong></p>{% endif %}
    <div id="rsperror" class="alert alert-error"></div>
    <div id="innlogging" style="position:fixed; top:0; right:0; padding: 1ex;">
      <div id="login-box" {% if req.user.is_authenticated %}style="display:none"{%endif%}>
        <a href="#login" class="btn" id="login">Logg inn</a>
        <div id="login-form" class="box" style="display:none">
          B: <input type="text" id="login-username"><br>
          P: <input type="password" id="login-password"><br>
          <button class="btn btn-primary" id="login-send">Start kverna</button><br>
          <button class="btn" id="login-cancel">Avbryt</button>
        </div>
      </div>
      <div id="logout-box" {% if not req.user.is_authenticated %}style="display:none"{%endif%}>
        <button class="btn" id="logout-send">Logg ut</button>
      </div>
    </div>
    <ul id="meny" class="nav nav-pills">
      <li><a href="/">Søk</a></li>
      <li><a href="/katalog">Katalog</a></li>
      <li><a href="/agent" class="require-authenticated">Overvåking</a></li>
      <li><a href="/historikk" class="require-authenticated">Historikk</a></li>
      <li><a href="/innsyn">Innsyn</a><span id="requestdoc">{% block requestinfo %}{% endblock %}</span></li>
      <li><a href="/om">Om</a></li>
      <li><a href="/nyheter">Nytt om ejeje</a></li>
    </ul>
    <div id="wrap">
      <div id="content">
  {%block body%}{%endblock%}
      </div>
      
      <div id="footer">
        <hr />
        <p><span class="legalese">© 2007,2010 hg</span> -- 
        <a href="http://code.google.com/p/ejeje/issues/entry">har du funnet en feil? fortell!</a></p>
      </div>
    </div>

  <div style="display:none;" id="statuspanel">
    <span id="statusBar" class="statusBar hidden">ejeje says hi!</span>
  </div>

{% if debug %}
<div id="debug" >
<ul>
{% for q in sql_queries %}
  <li>{{q.time}}: <b>{{q.sql}}</b></li>
{%endfor %}
</ul></div>
{% endif %}

    </body>

</html>
